package com.zijie.shop.order.api.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zijie.order.model.OrderItem;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface OrderItemMapper extends BaseMapper<OrderItem> {

    //    @Select("SELECT oi.*, o.order_no as orderNo, o.total_pay as totalPay, o.pay_time as payTime, o.update_time as updateTime, " +
//            "g.name as goodName, g.category_id as categoryId, g.price as goodPrice, g.description as goodDescription, g.sold as goodSold " +
//            "FROM order_item oi " +
//            "LEFT JOIN `order` o ON oi.order_id = o.id " +
//            "LEFT JOIN good g ON oi.good_id = g.id " +
//            "WHERE oi.order_id = #{orderId}")
//     OrderItem findByOrderId(@Param("orderId") Integer orderId);
    @Select("SELECT " +
            "o.order_no as orderNo, " +
            "o.member_id as memberId, " +
            "o.pay_type as payType, " +
            "o.pay_time as payTime, " +
            "o.update_time as updateTime, " +
            "g.pic as goodPic, " +
            "g.name as goodName, " +
            "b.name as brandName, " +
            "oi.deal_price as dealPrice, " +
            "g.description as goodDescription, " +
            "oi.count as count, " +
            "(oi.deal_price * oi.count) as subtotal " +
            "FROM order_item oi " +
            "LEFT JOIN `order` o ON oi.order_id = o.id " +
            "LEFT JOIN good g ON oi.good_id = g.id " +
            "LEFT JOIN brand b ON g.brand_id = b.id " +
            "WHERE oi.order_id = #{orderId}")
    List<Map<String, Object>> findOrderItemDetailsByOrderId(@Param("orderId") Integer orderId);

    int saveOrderItem(List<OrderItem> orderItems);
}